<template>
  <div id="shorticon">
    <swiper :options="swiperOpts" ref="iconSwiper">
      <swiper-slide v-for="(item,index) in icons" :key="index">
        <div class="item" v-for="icon in item" :key="icon.id">
          <div class="ico_wrapper" v-html="icon.img">
            <!-- <img :src="icon.imgUrl" alt class="ico"> -->
          </div>
          <div class="desc">{{icon.name}}</div>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'Shorticon',
  props: {
    iconList: Array
  },
  data() {
    return {
      swiperOpts: {
        loop: true
      }
    }
  },
  computed: {
    icons() {
      const tempArr = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!tempArr[page]) {
          tempArr[page] = []
        }
        tempArr[page].push(item)
      })
      return tempArr
    }
  }
}
</script>

<style  lang="stylus" scoped>
#shorticon >>>.swiper-container .ico_wrapper>img
  height  100%

#shorticon
  height 0
  padding-bottom 50%
  overflow hidden
  background-color #fff
  .item
    position relative
    float left
    width 25%
    height 0
    padding-bottom 25%
    overflow hidden
    .ico_wrapper
      position absolute
      left 0
      right 0
      top 0
      bottom 0.44rem
      box-sizing border-box
      padding 0.1rem 0
      text-align center
      img
        height 100%
    .desc
      position absolute
      left 0
      right 0
      bottom 0
      width 100%
      height 0.44rem
      line-height 0.44rem
      text-align center
</style>
